package com.dongnam.quanly.web.nghiepvu.quy.phieuthuchi;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;

import org.primefaces.context.RequestContext;
import org.primefaces.event.FileUploadEvent;
import org.primefaces.model.StreamedContent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.dongnam.quanly.common.controller.PhieuThuChiController;
import com.dongnam.quanly.common.model.PhieuThuChi;
import com.dongnam.quanly.common.model.enumtype.GioiTinh;
import com.dongnam.quanly.common.model.enumtype.HinhThuc;
import com.dongnam.quanly.web.UserBean;

@ManagedBean(name = "PhieuThuChiBean")
@SessionScoped
public class PhieuThuChiBean implements Serializable {

	private static final Logger logger = LoggerFactory.getLogger(PhieuThuChiBean.class);
	private static final long serialVersionUID = 1L;

	@ManagedProperty(value = "#{UserBean}")
	private UserBean userBean;
	private PhieuThuChiModel phieuThuChiModel;

	// for add PhieuThuChi
	private PhieuThuChi phieuThuChi;
	private boolean isEdit = false;

	// for download file
	private StreamedContent file;

	private PhieuThuChiController phieuThuChiController;

	private List<PhieuThuChi> listPhieuThuChi;

	private PhieuThuChi selectedPhieuThuChi;

	public PhieuThuChiBean() {
		super();
		phieuThuChi = new PhieuThuChi();
		listPhieuThuChi = new ArrayList<PhieuThuChi>();
	}

	public void downloadFileCSV() {
		// Todo
	}

	public void handleFileUpload(FileUploadEvent event) {
		// ToDo
	}

	public void resetFormAdd() {
		phieuThuChi = new PhieuThuChi();
	}

	public void notifyAdd() {
		isEdit = false;
		resetFormAdd();
	}

	public void notifyEdit(PhieuThuChi phieuThuChi) {
		isEdit = true;
		this.selectedPhieuThuChi = phieuThuChi;
		// ToDo
		// this.nhanvien.fillNhanVien(nhanvien);
	}

	public void removeDonHang() {

		if (this.selectedPhieuThuChi != null) {
			// ToDo
		}

	}

	public void save() {
		RequestContext context = RequestContext.getCurrentInstance();
		listPhieuThuChi.add(phieuThuChi);
		context.addCallbackParam("opSuccess", true);
	}

	public UserBean getUserBean() {
		return userBean;
	}

	public void setUserBean(UserBean userBean) {
		this.userBean = userBean;
	}

	public PhieuThuChiModel getPhieuThuChiModel() {
		return phieuThuChiModel;
	}

	public void setPhieuThuChiModel(PhieuThuChiModel phieuThuChiModel) {
		this.phieuThuChiModel = phieuThuChiModel;
	}

	public PhieuThuChi getPhieuThuChi() {
		return phieuThuChi;
	}

	public void setPhieuThuChi(PhieuThuChi phieuThuChi) {
		this.phieuThuChi = phieuThuChi;
	}

	public boolean isEdit() {
		return isEdit;
	}

	public void setEdit(boolean isEdit) {
		this.isEdit = isEdit;
	}

	public StreamedContent getFile() {
		return file;
	}

	public void setFile(StreamedContent file) {
		this.file = file;
	}

	public PhieuThuChiController getPhieuThuChiController() {
		if (phieuThuChiController == null) {
			phieuThuChiController = new PhieuThuChiController();
		}
		return phieuThuChiController;
	}

	public void setPhieuThuChiController(PhieuThuChiController phieuThuChiController) {
		this.phieuThuChiController = phieuThuChiController;
	}

	public PhieuThuChi getSelectedPhieuThuChi() {
		return selectedPhieuThuChi;
	}

	public void setSelectedPhieuThuChi(PhieuThuChi selectedPhieuThuChi) {
		this.selectedPhieuThuChi = selectedPhieuThuChi;
	}

	public List<PhieuThuChi> getListPhieuThuChi() {
		return listPhieuThuChi;
	}

	public void setListPhieuThuChi(List<PhieuThuChi> listPhieuThuChi) {
		this.listPhieuThuChi = listPhieuThuChi;
	}

	public HinhThuc[] getListHinhThuc() {
		return HinhThuc.values();
	}

	public GioiTinh[] getListGioiTinh() {
		return GioiTinh.values();
	}

}
